//
//  HZGoodsDetailPromotionModel.m
//  app
//
//  Created by 刘华舟 on 15/6/10.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HZGoodsDetailPromotionModel.h"

@implementation HZGoodsDetailPromotionModel

- (instancetype)initWithGiftList:(NSArray *)giftList promotion:(NSArray *)promotion gold:(NSString*)gold gold2RMB:(NSString *)gold2RMB{
    if (self = [super init]) {
        if (!(giftList.count||promotion.count||gold.length)) {
            self = nil;
        }else{
            _maxGift = @"1";
            NSMutableArray *giftArray = [NSMutableArray array];
            NSInteger index = 0;
            for (NSDictionary *cell in giftList) {
                HZGoodsCuXiaoCellViewModel *model = [[HZGoodsCuXiaoCellViewModel alloc] init];
                model.editable = NO;
                if (index == 0) {
                    model.selected = YES;
                    model.hide = NO;
                }else{
                    model.selected = NO;
                    model.hide = YES;
                }
                model.type = @"赠品";
                model.title = [cell stringForKey:APIKEY_mall_title nilValue:@""];
                model.productID = [cell stringForKey:APIKEY_mall_product_id nilValue:@"-1"];
                model.url = [cell stringForKey:APIKEY_mall_pic nilValue:@""];
                model.kind = @"detail";
                [giftArray addObject:model];
                index++;
            }
            _topCellArray = giftArray;
            _open = NO;
            if (giftArray.count) {
                if (_open) {
                    _topHeight = [UBO_SCREEN uh:kHZGoodsCuXiaoCellViewHeight*giftArray.count+2*kSizeMallViewMargin oh:-kHZGoodsCuXiaoCellPadding+(kHZGoodsCuXiaoCellPadding)*giftArray.count];
                }else{
                    _topHeight  = [UBO_SCREEN uh:kHZGoodsCuXiaoCellViewHeight + 2*kSizeMallViewMargin];
                }
                
            }else{
                _topHeight = 0;
            }
            
            
            NSMutableArray *proArray = [NSMutableArray array];
            for (NSDictionary *cell in promotion) {
                HZGoodsCuXiaoCellViewModel *model = [[HZGoodsCuXiaoCellViewModel alloc] init];
                model.editable = NO;
                model.selected = NO;
                model.hide = NO;
                model.name = [cell stringForKey:APIKEY_mall_name nilValue:@"活动"];
                model.type = [cell stringForKey:APIKEY_mall_name nilValue:@""];
                model.title = [cell stringForKey:APIKEY_mall_title nilValue:@""];
                model.url = [cell stringForKey:APIKEY_mall_url nilValue:@""];
                model.kind = @"web";
                [proArray addObject:model];
            }
            
            _middleCellArray = proArray;
            if (proArray.count) {
                _middleHeight = [UBO_SCREEN uh:(kHZGoodsCuXiaoCellViewHeight)*proArray.count+kSizeMallViewMargin oh:(kHZGoodsCuXiaoCellPadding)*(proArray.count)];
            }else{
                _middleHeight= 0;
            }
            
            
            NSMutableArray *zhediArray = [NSMutableArray array];
            if ([gold integerValue] > 0) {
                HZGoodsCuXiaoCellViewModel *model = [[HZGoodsCuXiaoCellViewModel alloc] init];
                model.editable = NO;
                model.selected = NO;
                model.hide = NO;
                model.name = @"百度";
                model.type = @"折抵";
                model.title = [NSString stringWithFormat:@"可用%@金豆折抵%0.2f元", gold, [gold integerValue]*[gold2RMB floatValue]];
                model.url = @"http://www.baidu.com";
                model.kind = @"none";
                [zhediArray addObject:model];
                _bottomHeight = [UBO_SCREEN uh:kHZGoodsCuXiaoCellViewHeight + 2*kSizeMallViewMargin];
                _bottomCellArray = zhediArray;
            }else{
                _bottomHeight = 0;
            }
        }
    }
    return self;
}

@end
